/*
 * Copyright 2010, 2011 Matt Oliveri
 *
 * This file is part of JConfigGen
 *
 * JConfigGen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JConfigGen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JConfigGen.  If not, see <http://www.gnu.org/licenses/>.
 */

package atma.jconfiggen.sax;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import atma.jconfiggen.Expr;
import atma.jconfiggen.Call;
import atma.jconfiggen.NoFX;

final class CallObjHFact extends HFact
{
	private static final AttrMatcher callobjAttr = new AttrMatcher("callobj","type","id","obj","method","args");

	CallObjHFact(SAXHandler s) {super(s);}

	ElemH make(ArrayList<Expr> pnt,Attributes attr) throws SAXException
	{
		String[] atv = callobjAttr.match(saxh.loc,attr);
		if (atv[3] == null) missAttr("callobj","method");
		int ln = saxh.loc.getLineNumber();
		if (atv[2] == null)
		{
			if (atv[4] != null) complain("callobj: Cannot have an args attribute but no obj attribute");
			return new CallObjH(saxh,pnt,ln,atv[0],atv[1],atv[3]);
		}
		String args = atv[4];
		if (args == null) args = "";
		pnt.add(new Call(saxh.config,ln,atv[0],atv[1],atv[2],atv[3],args));
		return new NoElemH(saxh,"Cannot have child elements in a callobj that uses the obj attribute");
	}
}
